package dav.mobile.garuda.states;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Delay;
import com.badlogic.gdx.scenes.scene2d.actions.FadeIn;
import com.badlogic.gdx.scenes.scene2d.actions.FadeOut;
import com.badlogic.gdx.scenes.scene2d.actions.Sequence;
import com.badlogic.gdx.scenes.scene2d.actors.Image;

import dav.mobile.garuda.components.Constants;
import dav.mobile.garuda.components.ResourceManager;

//Splash Screen
public class StateSplash extends State {
	//Stage
	Stage m_Stage;
	Action m_Action;
	
	Image m_Background;
	
	public StateSplash() {
		m_Stage = new Stage(Constants.GAME_WIDTH, Constants.GAME_HEIGHT, true);
		m_Action = Sequence.$(FadeIn.$(1.25f), Sequence.$(Delay.$(FadeOut.$(1.25f), 15.0f)));
		
		m_Background = new Image("Splash Screen", ResourceManager.m_Splash);
		m_Background.action(m_Action);
		m_Stage.addActor(m_Background);
	}
	
	@Override
	public void Update() {
		//If the action is done and resource were loaded
		if (m_Action.isDone()) {
			//Set flag as done
			m_Done = true;

			//Start Game
			SetState(new StateMenu());
		} else {
			//Update action
			m_Stage.act(Gdx.graphics.getDeltaTime());
		}
	}

	@Override
	public void Render() {
		m_Stage.draw();
	}
	
	@Override
	public void Dispose() {
		super.Dispose();
		
		m_Stage.removeActor(m_Background);
		
		m_Stage.dispose();
	}
	
}
